package com.ruoyi.customer.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customer.domain.CustomerLinkmane;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.customer.mapper.CustomerVisitMapper;
import com.ruoyi.customer.domain.CustomerVisit;
import com.ruoyi.customer.service.ICustomerVisitService;

/**
 * 拜访信息Service业务层处理
 *
 * @author aef
 * @date 2022-11-28
 */
@Service
public class CustomerVisitServiceImpl extends ServiceImpl<CustomerVisitMapper, CustomerVisit> implements ICustomerVisitService {

    /**
     * 查询拜访信息列表
     *
     * @param customerVisit 拜访信息
     * @return 拜访信息
     */
    @Override
    public List<CustomerVisit> selectCustomerVisitList(CustomerVisit customerVisit) {
        return getBaseMapper().selectCustomerVisitList(customerVisit);
    }

    @Override
    public boolean save(CustomerVisit customerVisit){
        Date visitDate = customerVisit.getVisitDate();
        Date newDate = new Date();
        if (visitDate == null){
            throw new ServiceException("日期不可为空");
        }

        if (visitDate.compareTo(newDate) > 0){
            throw new ServiceException("日期异常");
        }

        String username = SecurityUtils.getUsername();
        customerVisit.setInputUser(username);
        customerVisit.setInputTime(new Date());
        return super.save(customerVisit);
    }

    @Override
    public List<CustomerVisit> selevtByCustomerId(Long customerId) {
        List<CustomerVisit> customerVisitList = getBaseMapper().selectByCustomerId(customerId);
        return customerVisitList;
    }

}
